home *** CD-ROM | disk | FTP | other *** search
/ Magnum One / Magnum One (Mid-American Digital) (Disc Manufacturing).iso / d12 / c_toolbx.arc / BT_FREE.C < prev    next >
Encoding:
C/C++ Source or Header  |  1988-03-30  |  1.6 KB  |  49 lines

  1. /*  bt_free.c - maintain list of free index blocks */
  2. #include   "stdio.h"
  3. #include   "btree.h"
  4. #include   "bt_macro.h"
  5.  
  6. #define    FREE_LEVEL    (-1)    /* marks a block as free   */
  7. extern    IX_DESC    *pci ;    /* refers to index descriptor */
  8.                 /* for current function call  */
  9.  
  10. extern     BLOCK     spare_block ;    /* scratch block for splits and */
  11.                 /* compressing */
  12.  
  13. int make_free(fstart,filesize)    /* set up free block chain */
  14.   RECPOS   fstart ;        /* first free block */
  15.   RECPOS   filesize ;        /* size of the index file */
  16.   {
  17.      BLOCK *pb    ;
  18.      RECPOS   r ;
  19.      pb = & spare_block ;    /* scratch block */
  20.      pci->dx.ff = NULLREC ;    /* no blocks free to start */
  21.      for(r = fstart ; r < filesize ; r = r + IXB_SIZE  )
  22.     {  write_free(r,pb) ;  }
  23.   }
  24.  
  25. RECPOS    get_free()        /* grab a free block for use */
  26.   {
  27.      RECPOS   r , rt ;
  28.  
  29.      r = pci->dx.ff ;        /* get location of first free block */
  30.      if( r != NULLREC )     /* is there one ? */
  31.     {  read_if(r,&rt,sizeof(RECPOS)) ;   /* yes - find where it */
  32.        pci->dx.ff = rt ;    /* points & make it the 1st free */
  33.     }
  34.      return( r ) ;
  35.   }
  36.  
  37. int  write_free(r,pb)        /* write out a free block */
  38.   RECPOS   r ;            /* record number of block to free */
  39.   BLOCK    *pb ;        /* use this as scrstch space */
  40.   {
  41.      pb->lvl = FREE_LEVEL ;    /* mark block as free */
  42.      clr_mem(pb->entries,0,IXB_SPACE) ;     /* zero out the block */
  43.      pb->brec = pci->dx.ff ;    /* point to current 1st free block */
  44.      write_block(r,pb) ;    /* write the free block */
  45.      pci->dx.ff = r ;        /* make this block the first free */
  46.   }
  47.  
  48.  
  49.